﻿<UserControl x:Class="KarateSemaphore.SemaphoreControllerView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:vm="clr-namespace:KarateSemaphore" xmlns:System="clr-namespace:System;assembly=mscorlib"
             xmlns:core="clr-namespace:KarateSemaphore.Core;assembly=KarateSemaphore.Core" mc:Ignorable="d" 
        d:DataContext="{d:DesignInstance core:SemaphoreViewModel, IsDesignTimeCreatable=True}"
        d:DesignHeight="406" d:DesignWidth="540">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Style.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.Resources>
            <Style TargetType="Button">
                <Setter Property="Margin" Value="1" />
            </Style>
            <vm:MinutesSecondsConverter x:Key="timeConverter" />
            <vm:TernaryConverter x:Key="ternaryConverter" />
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="131*" />
            <RowDefinition Height="226*"/>
            <RowDefinition Height="25" />
            <RowDefinition Height="25"/>
            <RowDefinition Height="25"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*" />
            <ColumnDefinition Width="2*" />
            <ColumnDefinition Width="3*" />
        </Grid.ColumnDefinitions>
        <StackPanel 
            IsEnabled="{Binding Path=IsKnockdown, Converter={StaticResource ResourceKey=ternaryConverter}, ConverterParameter='False||True'}"
            Grid.Column="{Binding ElementName=semaphore, Path=IsInversed, Converter={StaticResource ResourceKey=ternaryConverter}, ConverterParameter='0||1'}"  
            Grid.RowSpan="2">
            <Border Background="{Binding Source={StaticResource ao}}" Height="15" />
            <vm:CompetitorControllerView DataContext="{Binding Ao}" IsEnabled="{Binding }" />
            <Border Background="{Binding Source={StaticResource ao}}" Height="15" />
        </StackPanel>
        <StackPanel 
            IsEnabled="{Binding Path=IsKnockdown, Converter={StaticResource ResourceKey=ternaryConverter}, ConverterParameter='False||True'}"
            Grid.Column="{Binding ElementName=semaphore, Path=IsInversed, Converter={StaticResource ResourceKey=ternaryConverter}, ConverterParameter='1||0'}"  
            Grid.RowSpan="2">
            <Border Background="{Binding Source={StaticResource aka}}" Height="15" />
            <vm:CompetitorControllerView DataContext="{Binding Aka}" />
            <Border Background="{Binding Source={StaticResource aka}}" Height="15" />
        </StackPanel>
        <Border Grid.Row="2"  Grid.Column="0">
            <Button 
                Content="Edit display text"
                Command="{Binding Path=RequestDisplayTextChange}" />
        </Border>
        <Border Grid.Row="2"  Grid.Column="1">
            <Button 
                Content="{Binding Path=IsKnockdown, Converter={StaticResource ResourceKey=ternaryConverter}, ConverterParameter='Cancel knockdown (F10)||Knockdown (F10)'}"
                Command="{Binding Path=ToggleKnockdownMode}" />
        </Border>
        <Border Grid.Row="3"  Grid.Column="0" Grid.ColumnSpan="2">
            <Button Content="Start / Pause (Space)" Command="{Binding Path=Time.StartStop}" />
        </Border>
        <vm:SemaphoreView x:Name="semaphore" Grid.Column="2" Margin="5" IsInversed="True" />
        <ListBox Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" ItemsSource="{Binding Path=EventManager.Events}" SelectedIndex="{Binding Path=EventManager.Position, Mode=OneWay}" DisplayMemberPath="Display" >
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Focusable" Value="False"/>
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>
        <Border Grid.Row="3" Grid.Column="2" Grid.RowSpan="2" Background="Yellow"></Border>
        <Grid 
            IsEnabled="{Binding Path=IsKnockdown, Converter={StaticResource ResourceKey=ternaryConverter}, ConverterParameter='False||True'}"
            Grid.Row="3" 
            Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button Content="&lt;" Command="{Binding Path=EventManager.Step}" CommandParameter="-1" />
            <Button Content="&gt;" Command="{Binding Path=EventManager.Step}" CommandParameter="1" Grid.Column="1" />
        </Grid>
        <TextBox Grid.ColumnSpan="2" 
                 Grid.Row="4" 
                 Margin="1"
                 Text="{Binding Path=ResetTime, Converter={StaticResource ResourceKey=timeConverter}}"  />
        <Button Grid.Column="2" Grid.Row="4" Content="Reset (F9)" Command="{Binding Path=Reset}" />
    </Grid>
</UserControl>
